home *** CD-ROM | disk | FTP | other *** search
/ Czech Logic, Card & Gambling Games / Logické hry.iso / hry / Fish Fillets / script / submarine / code.lua next >
Text File  |  2005-07-16  |  10KB  |  309 lines

  1.  
  2. -- -----------------------------------------------------------------
  3. -- Init
  4. -- -----------------------------------------------------------------
  5. local function prog_init()
  6.     initModels()
  7.     sound_playMusic("music/rybky06.ogg")
  8.     local pokus = getRestartCount()
  9.  
  10.  
  11.     -- -------------------------------------------------------------
  12.     local function prog_init_room()
  13.         local pom1, pom2, pomb1, pomb2 = 0, 0, false, false
  14.  
  15.         room.odjel = 0
  16.         room.qopatrne = 0
  17.         room.hulakat = random(30) + 10 * pokus
  18.         room.oci = 0
  19.         room.reklopatrne = 0
  20.  
  21.         return function()
  22.             if small:isTalking() or big:isTalking() then
  23.                 room.hulakat = -1
  24.             end
  25.             if room.odjel == 0 and big:isOut() and isReady(small) then
  26.                 room.odjel = 1
  27.                 switch(random(3)){
  28.                     [0] = function()
  29.                         addm(10, "zr-m-takfajn")
  30.                     end,
  31.                     [1] = function()
  32.                         addm(10, "zr-m-tojeon")
  33.                     end,
  34.                     [2] = function()
  35.                         addm(10, "zr-m-pockej")
  36.                     end,
  37.                 }
  38.             elseif room.qopatrne < 2 and room.reklopatrne == 1 and not small:isAlive() and small.X == 8 and isReady(big) then
  39.                 addv(3, "zr-v-vzdyt")
  40.                 room.qopatrne = 2
  41.             end
  42.             if room.qopatrne < 2 then
  43.                 if isReady(small) and small.X == 9 and isReady(big) and lahev.X == 8 and small:isLeft() and room.qopatrne == 0 then
  44.                     if no_dialog() then
  45.                         addv(1, "zr-v-opatrne")
  46.                         room.reklopatrne = 1
  47.                     else
  48.                         room.reklopatrne = 0
  49.                     end
  50.                     room.qopatrne = 1
  51.                 end
  52.             end
  53.             if room.qopatrne == 1 and not small:isLeft() then
  54.                 room.qopatrne = 0
  55.             end
  56.             if isReady(small) and isReady(big) and no_dialog() then
  57.                 if room.hulakat > 0 then
  58.                     room.hulakat = room.hulakat - 1
  59.                 elseif room.hulakat == 0 then
  60.                     room.hulakat = -1
  61.                     switch(random(3)){
  62.                         [0] = function()
  63.                             addv(3, "zr-v-hej")
  64.                         end,
  65.                         [1] = function()
  66.                             addv(3, "zr-v-halo")
  67.                         end,
  68.                         [2] = function()
  69.                             addv(3, "zr-v-jetunekdo")
  70.                         end,
  71.                     }
  72.                     switch(random(3)){
  73.                         [0] = function()
  74.                             addm(9, "zr-m-nervi")
  75.                         end,
  76.                         [1] = function()
  77.                             addm(9, "zr-m-nepovykuj")
  78.                         end,
  79.                         [2] = function()
  80.                             addm(9, "zr-m-tadyjsem")
  81.                         end,
  82.                     }
  83.                 end
  84.                 if no_dialog() and small.trpelivost == 0 then
  85.                     switch(random(2)){
  86.                         [0] = function()
  87.                             addm(0, "zr-m-obliceje")
  88.                         end,
  89.                         [1] = function()
  90.                             addm(0, "zr-m-prestan")
  91.                         end,
  92.                     }
  93.                     small.trpelivost = random(600) + 100
  94.                 end
  95.                 if no_dialog() and peri.cinnost == 7 and room.oci == 0 and random(100) < 50 then
  96.                     addm(5, "zr-m-komu")
  97.                     addv(10, "zr-v-nevim")
  98.                     room.oci = 1
  99.                 end
  100.             end
  101.         end
  102.     end
  103.  
  104.     -- -------------------------------------------------------------
  105.     local function prog_init_peri()
  106.         local pom1, pom2, pomb1, pomb2 = 0, 0, false, false
  107.  
  108.         peri.cinnost = 0
  109.  
  110.         return function()
  111.             local anim_table = {
  112.                 [0] = function()
  113.                     peri.delay = random(100) + 50
  114.                     peri.cinnost = 1
  115.                     peri.afaze = 0
  116.                 end,
  117.                 [1] = function()
  118.                     if peri.delay == 0 then
  119.                         peri.cinnost = peri.cinnost + 1
  120.                     else
  121.                         peri.delay = peri.delay - 1
  122.                     end
  123.                 end,
  124.                 [2] = function()
  125.                     peri.afaze = peri.cinnost - 1
  126.                     peri.cinnost = peri.cinnost + 1
  127.                 end,
  128.                 [8] = function()
  129.                     peri.delay = random(30) + 15
  130.                     peri.cinnost = peri.cinnost + 1
  131.                 end,
  132.                 [9] = function()
  133.                     if math.mod(game_getCycles(), 3) == 0 then
  134.                         peri.afaze = 6 + random(2)
  135.                     end
  136.                     if peri.delay == 0 then
  137.                         peri.cinnost = peri.cinnost + 1
  138.                     else
  139.                         peri.delay = peri.delay - 1
  140.                     end
  141.                 end,
  142.                 [10] = function()
  143.                     if random(100) < 30 then
  144.                         peri.cinnost = 20
  145.                     else
  146.                         peri.cinnost = peri.cinnost + 1
  147.                     end
  148.                 end,
  149.                 [11] = function()
  150.                     peri.delay = random(5) + 2
  151.                     peri.cinnost = peri.cinnost + 1
  152.                 end,
  153.                 [12] = function()
  154.                     if random(100) < 20 then
  155.                         peri.cinnost = peri.cinnost + 1
  156.                     end
  157.                 end,
  158.                 [13] = function()
  159.                     peri.afaze = 18 - peri.cinnost
  160.                     peri.cinnost = peri.cinnost + 1
  161.                 end,
  162.                 [16] = function()
  163.                     peri.afaze = peri.cinnost - 12
  164.                     peri.cinnost = peri.cinnost + 1
  165.                 end,
  166.                 [19] = function()
  167.                     if peri.delay == 0 then
  168.                         peri.cinnost = 8
  169.                     else
  170.                         peri.delay = peri.delay - 1
  171.                         peri.cinnost = 12
  172.                     end
  173.                 end,
  174.                 [20] = function()
  175.                     peri.afaze = 25 - peri.cinnost
  176.                     peri.cinnost = peri.cinnost + 1
  177.                 end,
  178.                 [26] = function()
  179.                     peri.cinnost = 0
  180.                 end,
  181.             }
  182.  
  183.             anim_table[3] = anim_table[2]
  184.             anim_table[4] = anim_table[2]
  185.             anim_table[5] = anim_table[2]
  186.             anim_table[6] = anim_table[2]
  187.             anim_table[7] = anim_table[2]
  188.  
  189.             anim_table[14] = anim_table[13]
  190.             anim_table[15] = anim_table[13]
  191.  
  192.             anim_table[17] = anim_table[16]
  193.             anim_table[18] = anim_table[16]
  194.  
  195.             anim_table[21] = anim_table[20]
  196.             anim_table[22] = anim_table[20]
  197.             anim_table[23] = anim_table[20]
  198.             anim_table[24] = anim_table[20]
  199.             anim_table[25] = anim_table[20]
  200.  
  201.             switch(peri.cinnost)(anim_table)
  202.             peri:updateAnim()
  203.         end
  204.     end
  205.  
  206.     -- -------------------------------------------------------------
  207.     local function prog_init_zrcadlo()
  208.         local pom1, pom2, pomb1, pomb2 = 0, 0, false, false
  209.  
  210.         zrcadlo:setEffect("mirror")
  211.     end
  212.  
  213.     -- -------------------------------------------------------------
  214.     local function prog_init_naboj()
  215.         local pom1, pom2, pomb1, pomb2 = 0, 0, false, false
  216.  
  217.         naboj.nabita = 0
  218.  
  219.         return function()
  220.             if naboj.nabita == 0 and naboj.X == 12 and naboj.Y == 8 then
  221.                 naboj.nabita = 1
  222.                 room:talk("zr-x-nabito")
  223.             end
  224.         end
  225.     end
  226.  
  227.     -- -------------------------------------------------------------
  228.     local function prog_init_small()
  229.         local pom1, pom2, pomb1, pomb2 = 0, 0, false, false
  230.         local xicht = 0
  231.  
  232.         small.trpelivost = random(50) + 30
  233.  
  234.         return function()
  235.             if not small:isLeft() and (xdist(small, zrcadlo) == -1 or xdist(small, zrcadlo) == -2) and ydist(small, zrcadlo) == 0 then
  236.                 if random(100) < 30 then
  237.                     xicht = random(9)
  238.                 end
  239.             else
  240.                 xicht = 0
  241.             end
  242.             if xicht ~= 0 then
  243.                 small:useSpecialAnim("head_all", xicht)
  244.             end
  245.         end
  246.     end
  247.  
  248.     -- -------------------------------------------------------------
  249.     local function prog_init_big()
  250.         local xicht = 0
  251.         return function()
  252.             if not big:isLeft() and (xdist(big, zrcadlo) == -1 or xdist(big, zrcadlo) == -2) and (zrcadlo.Y == big.Y or zrcadlo.Y == big.Y - 1) then
  253.                 if random(100) < 30 then
  254.                     xicht = random(8)
  255.                 end
  256.                 if small.trpelivost > 0 then
  257.                     small.trpelivost = small.trpelivost - 1
  258.                 end
  259.             else
  260.                 xicht = 0
  261.             end
  262.             if xicht ~= 0 then
  263.                 big:useSpecialAnim("head_all", xicht)
  264.             end
  265.         end
  266.     end
  267.  
  268.     -- --------------------
  269.     local update_table = {}
  270.     local subinit
  271.     subinit = prog_init_room()
  272.     if subinit then
  273.         table.insert(update_table, subinit)
  274.     end
  275.     subinit = prog_init_peri()
  276.     if subinit then
  277.         table.insert(update_table, subinit)
  278.     end
  279.     subinit = prog_init_zrcadlo()
  280.     if subinit then
  281.         table.insert(update_table, subinit)
  282.     end
  283.     subinit = prog_init_naboj()
  284.     if subinit then
  285.         table.insert(update_table, subinit)
  286.     end
  287.     subinit = prog_init_small()
  288.     if subinit then
  289.         table.insert(update_table, subinit)
  290.     end
  291.     subinit = prog_init_big()
  292.     if subinit then
  293.         table.insert(update_table, subinit)
  294.     end
  295.     return update_table
  296. end
  297. local update_table = prog_init()
  298.  
  299.  
  300. -- -----------------------------------------------------------------
  301. -- Update
  302. -- -----------------------------------------------------------------
  303. function prog_update()
  304.     for key, subupdate in pairs(update_table) do
  305.         subupdate()
  306.     end
  307. end
  308.  
  309.